package algorithm.sort.review3;

import java.util.Arrays;

public class Quick {
    public static void main(String[] args) {
        int[] arr = {19, 97, 9, 17, 1, 8, 27};
        sort(arr, 0, arr.length - 1);
        System.out.println(Arrays.toString(arr));
    }
    public static void sort(int[] arr,int left,int right){
        if (left < right){
            int pivot = arr[left];
            int l = left;
            int r = right;
            while (l < r){
                while (r > l && arr[r] >= pivot){
                    r--;
                }
                if (r > l) {
                    arr[l++] = arr[r];
                }
                while (r > l && arr[l] <= pivot){
                    l++;
                }
                if (r > l){
                    arr[r--] = arr[l];
                }
            }
            arr[l] = pivot;
            //左边
            sort(arr,left,l-1);
            //右边
            sort(arr,r+1,right);
        }
    }
}
